package com.service.user;

import com.dao.user.SysUserMapper;
import com.pojo.SysUser;
import com.service.user.SysUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public SysUser login(String account, String password) {
        SysUser sysUser = sysUserMapper.findByAccountAndPwd(account);
        if (sysUser == null){
            return null;
        }
        if (!password.equals(sysUser.getPassword())){
            return null;
        }
        return sysUser;
    }

    @Override
    public List<SysUser> list(@Param("realName") String realName, @Param("pageIndex") int pageIndex) {
        List<SysUser> list = sysUserMapper.list(realName, pageIndex, pageIndex);
        return list;
    }

    @Override
    public int count(String realName) {
        int totalCount = sysUserMapper.count(realName);
        return totalCount;
    }

    @Override
    public int add(SysUser sysUser) {
       return sysUserMapper.add(sysUser);
    }

    @Override
    public int delete(int id) {
        return sysUserMapper.delete(id);
    }

    @Override
    public SysUser sysUser(int id) {
        SysUser sysUser = sysUserMapper.sysUser(id);
       return sysUser;
    }

    @Override
    public int update(SysUser user) {
        return sysUserMapper.update(user);
    }

    @Override
    public SysUser getAccountExist(String account) {
        return sysUserMapper.findByAccountAndPwd(account);
    }

    @Override
    public int updatePassword(@Param("account") String account,@Param("password") String password) {
        return sysUserMapper.updatePassword(account,password);
    }
}
